# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Alex Yam <alex@alexyam.com>
pkgname=librime
pkgver=1.7.2_git20220126
_gitrev=be0ea833456bba4319103915c1a819d3fa885728
pkgrel=5
pkgdesc="Rime input method engine"
url="https://github.com/rime/librime"
arch="all"
license="BSD-3-Clause"
makedepends="
	boost-dev
	capnproto-dev
	cmake
	leveldb-dev
	libmarisa-dev
	opencc-dev
	yaml-cpp-dev
	"
checkdepends="gtest-dev"
subpackages="$pkgname-dev"
source="$pkgname-$_gitrev.tar.gz::https://github.com/rime/librime/archive/$_gitrev.tar.gz"
builddir="$srcdir"/$pkgname-$_gitrev

if [ "$CARCH" = riscv64 ]; then
	# no glog on riscv64, disable logging (enabled by default)
	riscv64_logging_off="-DENABLE_LOGGING=OFF"
else
	makedepends="$makedepends glog-dev"
	riscv64_logging_off="-DENABLE_LOGGING=ON"
fi

build() {
	cmake -B build \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_FULL_DATADIR=/usr/share \
		-DCMAKE_INSTALL_FULL_LIBDIR=/usr/lib \
		-DBOOST_USE_CXX11=ON \
		-DBOOST_USE_SIGNALS2=ON \
		-DBUILD_DATA=ON \
		-DBUILD_MERGED_PLUGINS=OFF \
		-DBUILD_SAMPLE=OFF \
		-DBUILD_SEPARATE_LIBS=OFF \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_STATIC=OFF \
		-DBUILD_TEST=$(want_check && echo ON || echo OFF) \
		-DENABLE_ASAN=OFF \
		-DENABLE_EXTERNAL_PLUGINS=ON \
		-DINSTALL_PRIVATE_HEADERS=ON \
		$riscv64_logging_off
	cmake --build build
}

check() {
	cd build && ctest --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	cd "$pkgdir"
	# move rime/RimeConfig.cmake from /usr/share/cmake to /usr/lib/cmake
	mv -v usr/share/cmake usr/lib/cmake
	# create missing default paths for other ime packages to find rime data
	# (e.g. ibus-rime uses -DRIME_DATA_DIR="/usr/share/rime-data")
	mkdir -v usr/share/rime-data usr/lib/rime-plugins
}

sha512sums="
11b521991071679ac5a107daad2607e2494259bfd9cbb037a8526ffe8d4f81f3bdaeaa64598751b5994a6d6f1844df2016d95e8b848131a57f950ea50bcdeec9  librime-be0ea833456bba4319103915c1a819d3fa885728.tar.gz
"
